import axios from './ajax'
import { ResDataType } from './types'

export async function getUserInfoService(): Promise<ResDataType> {
  const url = `/api/user/info`

  return (await axios.get(url)) as ResDataType
}

export async function registerUserService(
  username: string,
  password: string,
  nickname: string = username
): Promise<ResDataType> {
  const url = '/api/user/register'

  return (await axios.post(url, { data: { username, password, nickname } })) as ResDataType
}

export async function loginService(username: string, password: string): Promise<ResDataType> {
  const url = '/api/user/login'

  return (await axios.post(url, { data: { username, password } })) as ResDataType
}
